<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>默认样式信息窗体</title>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
    <style>
        html,
        body,
        #container {
            height: 100%;
            width: 100%;
        }

        .content-window-card {
            position: relative;
            box-shadow: none;
            bottom: 0;
            left: 0;
            width: auto;
            padding: 0;
        }

        .content-window-card p {
            height: 2rem;
        }

        .custom-info {
            border: solid 1px silver;
        }

        div.info-top {
            position: relative;
            background: none repeat scroll 0 0 #F9F9F9;
            border-bottom: 1px solid #CCC;
            border-radius: 5px 5px 0 0;
        }

        div.info-top div {
            display: inline-block;
            color: #333333;
            font-size: 14px;
            font-weight: bold;
            line-height: 31px;
            padding: 0 10px;
        }

        div.info-top img {
            position: absolute;
            top: 10px;
            right: 10px;
            transition-duration: 0.25s;
        }

        div.info-top img:hover {
            box-shadow: 0px 0px 5px #000;
        }

        div.info-middle {
            font-size: 12px;
            padding: 10px 6px;
            line-height: 20px;
        }

        div.info-bottom {
            height: 0px;
            width: 100%;
            clear: both;
            text-align: center;
        }

        div.info-bottom img {
            position: relative;
            z-index: 104;
        }

        span {
            margin-left: 5px;
            font-size: 11px;
        }

        .info-middle img {
            float: left;
            margin-right: 6px;
        }
    </style>
</head>

<body>
    <div style="height: 500px; width: 500px;" id="container">
        这里是地图控件的容器
    </div>
    <script src="https://webapi.amap.com/maps?v=1.4.15&key=b886fb12aa5e241d4af74e4fb90bee64"></script>
    <script>    //地图初始化时，在地图上添加一个marker标记,鼠标点击marker可弹出自定义的信息窗体
        var map = new AMap.Map("container", {
            resizeEnable: true,
            center: [116.481181, 39.989792],
            zoom: 16
        });

        var lon = $('#longitude').val()
        var lat = $('#latitude').val();
        var map;
        if (lon > 0) {//初始化到已有地点
            map = new AMap.Map('container', {
                zoom: 20,
                resizeEnable: true,
                center: [lon, lat],
                viewMode: '3D'
            });
        } else {//初始化到默认地点
            map = new AMap.Map('container', {
                zoom: 12,
                resizeEnable: true,
                viewMode: '3D'
            });
        }
        //此插件用来显示当前位置，可在引入API时一同引入
        map.plugin('AMap.Geolocation', function () {
            var geolocation = new AMap.Geolocation({
                enableHighAccuracy: true,
                timeout: 10000,
                buttonOffset: new AMap.Pixel(10, 20),
                zoomToAccuracy: true,
                buttonPosition: 'RB'
            });
            map.center = geolocation;
            map.addControl(geolocation);//地图控件右下角显示当前位置
        });

        var geocoder, marker;
        if (!marker) {
            marker = new AMap.Marker();
            map.add(marker);
        }

        var lnglat;
        //地图点击时，获取点击地经纬度
        map.on('click', function (e) {
            lnglat = e.lnglat;
            regeoCode();
        })
        function regeoCode() {
            if (!geocoder) {
                geocoder = new AMap.Geocoder();
            }

            if (!marker) {
                marker = new AMap.Marker();
                map.add(marker);
            }
            marker.setPosition(lnglat);//设置标记的位置
            geocoder.getAddress(lnglat, function (status, result) {
                if (status === 'complete' && result.regeocode) {
                    var address = result.regeocode.formattedAddress;
                    //$('#address').val(address);//点击地名称
                    //$('#longitude').val(lnglat.lng);//经纬度
                    //$('#latitude').val(lnglat.lat);
                }
            });
            marker.setMap(map);//在地图上显示一个标记
        }

    </script>
</body>

</html>